package com.bluestone.run;

import java.util.List;

import com.bluestone.context.ActionContext;
import com.bluestone.context.CommandContext;
import com.bluestone.context.IContext;
import com.bluestone.scripts.ActionScript;
import com.bluestone.scripts.Command;

public class CommandController extends BaseController {

	@Override
	boolean executeContext(IContext context) {
		boolean flag = false;
		CommandContext commandContext = (CommandContext)context;
		Command command = commandContext.getCommand();
		commandContext.addExecuteLog("run command "+command.getName());
		List actions = command.getActions();
		ActionController controller = new ActionController();
		for(int i=0; i<actions.size(); i++){
			ActionScript action = (ActionScript) actions.get(i);
			ActionContext actionContext = commandContext.getActionContext(action);
			flag = controller.execute(actionContext);
			if(!flag){
				break;
			}
		}
		commandContext.addExecuteLog("run command "+command.getName()+"-->"+flag);
		return flag;
		
	}



}
